//package me.weishu.reflection;
//
//import static android.os.Build.VERSION.SDK_INT;
//import static me.weishu.reflection.BootstrapClass.exemptAll;
//
//import android.content.Context;
//import android.os.Build;
//import android.text.TextUtils;
//import android.util.Base64;
//
//import androidx.annotation.RequiresApi;
//
//import java.io.File;
//import java.io.FileOutputStream;
//import java.lang.reflect.Method;
//
//import dalvik.system.DexFile;
//
///**
// * @author weishu
// * @date 2018/6/7.
// */
//
//public class Reflection {
//    private static final String TAG = "Reflection";
//
//    private static final String DEX = "ZGV4CjAzNQCl4EprGS2pXI/v3OwlBrlfRnX5rmkKVdN0CwAAcAAAAHhWNBIAAAAAAAAAAMgKAABEAAAAcAAAABMAAACAAQAACwAAAMwBAAAMAAAAUAIAAA8AAACwAgAAAwAAACgDAADsBwAAiAMAABYGAAAYBgAAHQYAACcGAAAvBgAAPwYAAEsGAABbBgAAcAYAAIIGAACJBgAAkQYAAJQGAACYBgAAnAYAAKIGAAClBgAAqgYAAMUGAADrBgAABwcAABsHAAAuBwAARAcAAFgHAABsBwAAgAcAAJcHAACzBwAA2wcAAAIIAAAlCAAAMQgAAEIIAABLCAAAUAgAAFMIAABhCAAAbwgAAHMIAAB2CAAAeggAAI4IAACjCAAAuAgAAMEIAADaCAAA3QgAAOUIAADwCAAA+QgAAAoJAAAeCQAAMQkAAD0JAABFCQAAUgkAAGwJAAB0CQAAfQkAAJgJAAChCQAArQkAAMUJAADXCQAA3QkAAOUJAADzCQAACwAAABEAAAASAAAAEwAAABQAAAAVAAAAFwAAABgAAAAZAAAAGgAAABsAAAAcAAAAHQAAAB4AAAAjAAAAJwAAACkAAAAqAAAAKwAAAAwAAAAAAAAA3AUAAA0AAAAAAAAA5AUAAA4AAAAAAAAA7AUAAA8AAAACAAAAAAAAABAAAAAGAAAA+AUAABAAAAAKAAAAAAYAACMAAAAOAAAAAAAAACYAAAAOAAAACAYAACcAAAAPAAAAAAAAACgAAAAPAAAACAYAACgAAAAPAAAAEAYAAAIAAAA/AAAAAwAAACEAAAALA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ZW0uVk1SdW50aW1lAAFlAAZleGVtcHQACWV4ZW1wdEFsbAAHZm9yTmFtZQAPZnJlZS1yZWZsZWN0aW9uABJnZXRBcHBsaWNhdGlvbkluZm8AEWdldERlY2xhcmVkTWV0aG9kAApnZXRSdW50aW1lAAZpbnZva2UAC2xvYWRMaWJyYXJ5ABhtZS53ZWlzaHUuZnJlZXJlZmxlY3Rpb24ABm1ldGhvZAAHbWV0aG9kcwAZcmVmbGVjdCBib290c3RyYXAgZmFpbGVkOgAHcmVsZWFzZQAKc1ZtUnVudGltZQAWc2V0SGlkZGVuQXBpRXhlbXB0aW9ucwAQdGFyZ2V0U2RrVmVyc2lvbgAEdGhpcwAGdW5zZWFsAAx1bnNlYWxOYXRpdmUADnZtUnVudGltZUNsYXNzAAYABw4AFgAHDmr/AwEyCwEVEAMCNQvwBAREBhcBEg8DAzYLARsPqQUCBQMFBBkeAwAvCgAOAAcOACwBOgcOADYBOwcsnRriAQEDAC8KHgBIAAcOAA0ABw4AEwEtBx1yGWtaAAYXOBc8HxcABAEXAQEXBgEXHwYAAQACGQEZARkBGQEZARkGgYAEiAcDAAUACBoBCgEKB4iABKAHAYGABLQJAQnMCQGJAfQJAQnMCgEAAwALGgyBgAT4CgEJkAsBigIAAAAADgAAAAAAAAABAAAAAAAAAAEAAABEAAAAcAAAAAIAAAATAAAAgAEAAAMAAAALAAAAzAEAAAQAAAAMAAAAUAIAAAUAAAAPAAAAsAIAAAYAAAADAAAAKAMAAAEgAAAIAAAAiAMAAAEQAAAHAAAA3AUAAAIgAABEAAAAFgYAAAMgAAAIAAAAAwoAAAUgAAADAAAAZgoAAAAgAAADAAAAeAoAAAAQAAABAAAAyAoAAA==";
//
//    private static native int unsealNative(int targetSdkVersion);
//
//    public static int unseal(Context context) {
//        if (SDK_INT < 28) {
//            // Below Android P, ignore
//            return 0;
//        }
//
//        // try exempt API first.
//        if (exemptAll()) {
//            return 0;
//        }
//        if (unsealByDexFile(context)) {
//            return 0;
//        }
//
//        return -1;
//    }
//
//    private static boolean unsealByDexFile(Context context) {
//        byte[] bytes = Base64.decode(DEX, Base64.NO_WRAP);
//        File codeCacheDir = null;
//        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
//            codeCacheDir = getCodeCacheDir(context);
//        }
//        if (codeCacheDir == null) {
//            return false;
//        }
//        File code = new File(codeCacheDir, System.currentTimeMillis() + ".dex");
//        try {
//
//            try (FileOutputStream fos = new FileOutputStream(code)) {
//                fos.write(bytes);
//            }
//
//            DexFile dexFile = new DexFile(code);
//            // This class is hardcoded in the dex, Don't use BootstrapClass.class to reference it
//            // it maybe obfuscated!!
//            Class<?> bootstrapClass = dexFile.loadClass("me.weishu.reflection.BootstrapClass", null);
//            Method exemptAll = bootstrapClass.getDeclaredMethod("exemptAll");
//            return (boolean) exemptAll.invoke(null);
//        } catch (Throwable e) {
//            e.printStackTrace();
//            return false;
//        } finally {
//            if (code.exists()) {
//                //noinspection ResultOfMethodCallIgnored
//                code.delete();
//            }
//        }
//    }
//
//    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
//    private static File getCodeCacheDir(Context context) {
//        if (context != null) {
//            return context.getCodeCacheDir();
//        }
//        String tmpDir = System.getProperty("java.io.tmpdir");
//        if (TextUtils.isEmpty(tmpDir)) {
//            return null;
//        }
//        File tmp = new File(tmpDir);
//        if (!tmp.exists()) {
//            return null;
//        }
//        return tmp;
//    }
//}
